<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="e" uri="/easytogo-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>新角色</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<e:base/>   
	<script type="text/javascript">
        setBodyOnLoad(doEventHandler);
        var t;
        function doEventHandler(){
	        t = uiManager.getObject("resourceTree");
            var ids = "${resourceIds}";
            var idArray = ids.split(",");
            setTimeout(function(){//树加载完成之后再选中,需要延时一下,(应该是个bug)
	            for(var i=0;i<idArray.length;i++){
	            	var id = idArray[i];
	            	t.setCheck(id, true);
	            }
            },200);
        }
        function sub_new(){
			var id=$("#id").val();
			var resourceIds = t.getAllChecked();
			var url="${pageContext.request.contextPath}/admin/role_saveNew.action?admin=${admin}";
			if(id!=null&&id!=""){//如果有id说明是更新
				var url="${pageContext.request.contextPath}/admin/role_saveUpdate.action?admin=${admin}";
			}
			$.ajax({
				type: "post",
				url: url,
				data: {"id":id,"name":$("#name").val(),"resourceIds":resourceIds},
				dataType:"html",
				success: function(msg){
			  		if(msg=="failed"){
						alert("保存失败!");
					}else{
						if("${successAlert}"=="1"){
							alert("保存成功!");
						}
						parent.afterSave();
					}
				}
			}); 
		}
    </script>
  </head>
  
  <body>
	   <table>
	    	<tr>
	    		<td>名称</td>
	    		<td>
	    			<input id="name" name="name" type="text" value="${name}"/>
	    			<input id="id" name="id" type="hidden" value="${id}"/>
	    		</td>
	    	</tr>
	    	<tr>
	    		<td>功能</td>
	    		<td>
	    			<e:tree id="resourceTree" treeLoadUrl="${pageContext.request.contextPath }/common/tree_getTreeData.action?admin=${admin}" height="100%" isEnableCheckBoxes="true" isEnableThreeStateCheckboxes="false"/>
	    		</td>
	    	</tr>
	    	<tr>
	    		<td colspan="2" align="center"><input type="button" value="提交" onclick="sub_new();"/></td>
	    	</tr>
	    </table>
  </body>
</html>
